<!-- 发送时间 -->

<template>
  <div>
    <FormRadio
      label="发送类型"
      bind="questionnaireType"
      :dict="DICT.SEND_TYPE"
      initFirst
      isBtn
      onlyAdd
      required
      @change="changeType"
    />

    <FormSlot v-if="one.questionnaireType === 2" label="发送时间" bind="sendTime" tipPre="请选择" future half required>
      <FormDate label="日期" bind="sendDate" format future noLabel half @change="changeSendTime" />
      <FormSelect label="时间" bind="sendHour" :dict="DICT.HOUR_MINUTE" double noLabel half @change="changeSendTime" />
    </FormSlot>

    <div v-if="one.questionnaireType === 3">
      <FormRadio
        label="循环周期"
        bind="repeatType"
        :dict="DICT.SEND_CYCLE"
        initFirst
        isBtn
        required
        @change="changeCycle"
      />
      <FormCheckbox
        v-if="one.repeatType === 2"
        key="1"
        label="选择每周"
        bind="repeatConfig_week"
        :dict="DICT.SEND_WEEK"
        :hasAll="false"
        tipPre="请"
        required
      />
      <FormCheckbox
        v-if="one.repeatType === 3"
        key="2"
        label="选择每月"
        bind="repeatConfig_month"
        :dict="DICT.SEND_MONTH"
        :hasAll="false"
        tipPre="请"
        required
      />
      <EasyRow col2>
        <FormSelect label="选择时间" bind="repeatConfig_time" :dict="DICT.HOUR_MINUTE" tipPre="请" double required />
      </EasyRow>
    </div>
  </div>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'SendTime',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixWeb()],

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 切换类型
     */
    changeType() {
      CORE.merge(this.one, {
        sendTime: undefined,
        repeatType: undefined,
        repeatConfig_week: [],
        repeatConfig_month: [],
        repeatConfig_time: undefined,
      })
    },

    /**
     * 切换发送时间
     */
    changeSendTime() {
      const { sendDate, sendHour } = this.one
      this.one.sendTime = sendDate && sendDate ? CORE.timeNum(`${sendDate} ${sendHour}`) : undefined
    },

    /**
     * 切换周期
     */
    changeCycle() {
      CORE.merge(this.one, {
        repeatConfig_week: [],
        repeatConfig_month: [],
      })
    },
  },
}
</script>
